<!DOCTYPE html>
<html lang="en">


<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请先登录！</title>

    <!-- 弹出框登录界面样式 -->
    <style>
        form {
            width: 280px;
            height: 180px;
            margin: 9px auto;
            padding: 20px;
            border: 1px solid #ccc;
            background-color: azure;
        }
        
        .right {
            float: right;
        }
        
        .register {
            float: right;
            margin: 10px;
            font-size: 10px;
        }
        
        .agreement {
            float: left;
            margin: 10px 25px;
            font-size: 10px;
        }
        
        p {
            float: left;
            font-size: 10px;
        }
        
        p:nth-of-type(2) {
            position: relative;
            left: 20px;
        }
        
        .box {
            display: block;
            margin-top: 50px;
        }
        
        .reset {
            margin-left: 25px;
            border-radius: 10px;
        }
        
        .login {
            float: right;
            margin-right: 25px;
            border-radius: 10px;
        }
        
        h1 {
            margin: 8px;
            text-align: center;
        }
        
        .block1 .block2 {
            height: 300px;
        }
    </style>

    <!-- 弹出框框架生成 -->
    <style>
        .dialog {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }
        
        .dialog-content {
            background-color: #fefefe;
            margin: 15% auto;
            border: 1px solid #888;
            width: 350px;
            height: 300px;
        }
        
        .close-button {
            /* 关闭按钮的样式设置 */
            position: relative;
            float: right;
            width: 25px;
            padding: 0;
            margin: 0;
            border: none;
            cursor: pointer;
        }
        
        .close-button:hover {
            background-color: red;
        }
        
        button {
            margin-top: 10px;
        }
        
        input {
            margin-bottom: 10px;
        }
    </style>

    <style>
        .main_a {
            color: white;
            background-color: rgba(0, 0, 0, 0.5);
            font-size: large;
            display: block;
            float: left;
            text-decoration: none;
            border-radius: 5px;
            border: 2px solid;
            padding: 5px;
            margin: 5px;
        }
        
        .main_a:active {
            background: rgba(0, 255, 0, 1);
        }
        
        .main_a:hover {
            background-color: #0099E5;
        }
    </style>



    <script>
        // 提示登录时点击确认按钮显示弹出框登录界面
        function confirmLogin(link) {
            var result = confirm("请先登录！");
            if (result) {
                document.getElementById("dialog").style.display = "block";
            }
        }

        function DirectLogin(button) {
            document.getElementById("dialog").style.display = "block";
        }

        // 弹出框关闭
        function closeDialog() {
            document.getElementById("dialog").style.display = "none";
        }
    </script>

    <!-- 登录操作判断 -->
    <script>
        function login() {
            // 获取style属性值
            // var block1 = document.getElementById("block1");
            // var block2 = document.getElementById("block2");
            // 获取注册用户名和密码的输入框的值
            var register_username = document.getElementById("register_username").value;
            var register_password = document.getElementById("register_password").value;
            // 验证用户名和密码——注册界面
            if (document.getElementById("block1").style.display === "none") {
                // 检测用户名或密码是否为空
                if (register_username === "" || register_password === "") {
                    alert("用户名或密码不能为空！")
                } else {
                    alert("注册成功！请返回登录页面进行登录")
                    block1.style.display = "block";
                    block2.style.display = "none";
                }
            } else if (document.getElementById("block2").style.display === "none") {
                // 获取登录用户名和密码的输入框的值
                var username = document.getElementById("username").value;
                var password = document.getElementById("password").value;
                // 获取复选框数据
                var checkbox = document.getElementById("checkbox");
                // 验证用户名和密码——登录界面
                if (username === "admin" && password === "123" && checkbox.checked) {
                    // 加载新页面
                    window.location.href = "index_raw.html";
                } else if (username == register_username && password == register_password && checkbox.checked) {
                    // 加载新页面
                    window.location.href = "index_raw.html";
                } else if (!checkbox.checked) {
                    // 检查复选框是否选中
                    alert("请仔细阅读并勾选登录协议和隐私政策");
                    return;
                } else if (username === "" || password === "") {
                    // 检测用户名或密码是否为空(双等判断会进行类型转换，三等是纯比较)
                    alert("用户名或密码不能为空！")
                } else {
                    alert("用户名或密码错误");
                }
            }

        }
    </script>

    <!-- 注册登录页面切换 -->
    <script>
        function toggleBlocks() {
            var block1 = document.getElementById("block1");
            var block2 = document.getElementById("block2");

            if (block1.style.display === "none") {
                block1.style.display = "block";
                block2.style.display = "none";
            } else {
                block1.style.display = "none";
                block2.style.display = "block";
            }
        }
    </script>
</head>

<body>
    <a class="main_a" href="#" onclick="confirmLogin()">第一章</a>
    <a class="main_a" href="#" onclick="confirmLogin()">第二章</a>
    <a class="main_a" href="#" onclick="confirmLogin()">第三章</a>
    <a class="main_a" href="#" onclick="confirmLogin()">第四章</a>

    <!-- 弹框登录 -->
    <div id="dialog" class="dialog">
        <div class="dialog-content">
            <!-- 弹框内容 -->
            <button class="close-button" onclick="closeDialog()">x</button>
            <div id="block1" class="block1">
                <h1>&nbsp;&nbsp;&nbsp;LOGIN</h1>
                <form action="#" method="post">
                    用户名：
                    <input class="right" type="text" id="username" placeholder="请输入您的用户名" maxlength="5">
                    <br><br>密码：
                    <input class="right" type="password" id="password" placeholder="请输入您的密码">
                    <div class="register"><a href="#" onclick="toggleBlocks()">快速注册</a> | <a href="第四章/登录/协议与政策.html">忘记密码？</a></div><br>
                    <div class="box">
                        <input type="reset" class="reset" value="清空">
                        <input class="login" type="button" value="登录" onclick="login()">
                    </div>
                    <div class="agreement">
                        <input type="checkbox" id="checkbox"> 阅读并接受
                        <a href="第四章/登录/协议与政策.html">登录协议</a> 和
                        <a href="第四章/登录/协议与政策.html">隐私政策</a>
                    </div>
                </form>
            </div>
            <div id="block2" class="block2" style="display: none;">
                <h1>&nbsp;&nbsp;&nbsp;REGISTER</h1>
                <form action="#" method="post" id="link_login">
                    用户名：
                    <input class="right" type="text" id="register_username" placeholder="请输入您的用户名" maxlength="5">
                    <br><br>密码：
                    <input class="right" type="password" id="register_password" placeholder="请输入您的密码">
                    <div class="register"><a href="#" onclick="toggleBlocks()">已有账号？快速登录</a></div><br>
                    <div class="box">
                        <input type="reset" class="reset" value="清空">
                        <input class="login" type="button" value="注册" onclick="login()">
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>

</html>